'use strict';

const BaseController = require('./baseController');


class ProjectController extends BaseController {
    async index() {

    }

    //获取任务列表
    async list() {
        const { ctx } = this;
        let params = ctx.query;

        let { list, count } = await ctx.service.project.list(params);

        let projectDtoList = [];

        projectDtoList = list.map( async item => {
            let newData = ctx.helper.toCamel(item);
            newData.createNserName = await ctx.service.user.getUserName(item.create_user_id);
            newData.headUserName= await ctx.service.user.getUserName(item.head_user_id);
            newData.statusLabel = ctx.helper.getProjectStatusLabel(newData.status);
            return newData;
        });

        projectDtoList = await Promise.all(projectDtoList);

        this.jsonSuccess({
            data: projectDtoList,
            count: count
        });
    }


    //创建任务
    async save(){
        const { ctx } = this;
        
        let params = ctx.request.body;

        let data = await ctx.service.project.save(params);

        ctx.body = JSON.stringify({code:0, data:data});
    }

    //删除任务
    async del(){
        const { ctx } = this;
        
        let params = ctx.request.body;

        let data = await ctx.service.project.del(params.id);

        ctx.body = JSON.stringify({code:0, data:data});
    }

}

module.exports = ProjectController;
